package gyb.rasa.controller;


import gyb.rasa.common.utils.Result;
import gyb.rasa.entity.Video;
import gyb.rasa.entity.vo.Department;
import gyb.rasa.service.VideoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 郜宇博
 * @since 2023-04-11
 */
@RestController
@RequestMapping("/api")
public class VideoController {
    private final VideoService videoService;

    public VideoController(VideoService videoService) {
        this.videoService = videoService;
    }

    @ApiOperation("获取指定疾病种类的视频")
    @GetMapping("videos")
    public Result getVideosByDisease(@RequestParam("disease") String disease) {
        List<Video> videoList = new ArrayList<>();
        if (StringUtils.isEmpty(disease) || "undefined".equals(disease)){
            videoList = videoService.getVideosByDisease("感冒");
        }else {
            videoList = videoService.getVideosByDisease(disease);
        }
        return videoList!=null?Result.ok().data("videosList", videoList):Result.error().message("获取视频失败");
    }
    @ApiOperation("获取指定ID的视频")
    @GetMapping("video")
    public Result getVideosByVid(@RequestParam("vid") String vid) {
        //System.out.println(vid);
        Video video = videoService.getVideosByVid(vid);
        return video!=null?Result.ok().data("video", video):Result.error().message("获取视频失败");
    }
    @ApiOperation("获取二级科、疾病列表")
    @GetMapping("departments")
    public Result getDepartmentsWithDisease(){
        List<Department> departments = videoService.getDepartmentsWithDisease();
        return departments!=null?Result.ok().data("departments", departments):Result.error().message("获取疾病列表失败");
    }

}

